
class FieldGroup < ContentWithFields

  attribute :name

  def on_plug klass, name, definition
    @name = name
    (@@__fields[self.class] || []).each { |name, field|
      field.on_plug(klass, name, definition)
      #field.freeze
    }
  end

  def self.define_field klass, name, definition
    field_instance = definition[0]
    (@@__fields[klass] ||= {})[name.to_s] = field_instance
  end

  def creator e
    super
  end


  class Test < FwTest

    class MyColorField < Thing
      attr_accessor :called_with

      def on_plug *a
        @called_with = a
      end
    end

    def test_field_group_plugs_field_into_its_parent_when_plugged
      color = MyColorField.new()
      inner = Class.new(FieldGroup) {
        field :color, color
      }

      eq color.called_with, nil

      outer = Class.new(ContentWithFields) {
        field :inner, inner.new
      }

      eq color.called_with, [outer, "color", []]

    end
  end
end